from dash import Dash, html
import dash_ag_grid as dag
import pandas as pd

app = Dash(__name__)


df = pd.read_csv(
    "olympic-winners.csv"
)

app.layout = html.Div(
    [
        dag.AgGrid(
            id="master-detail-aggregate-example",
            enableEnterpriseModules=True,
            columnDefs=[
                    {'field': 'country', 'rowGroup': True, 'hide': True},
                    {'field': 'year', 'rowGroup': True, 'hide': True},
                    {'field': 'athlete'},
                    {'field': 'gold', 'aggFunc': 'sum'},
                    {'field': 'silver', 'aggFunc': 'max'},
                    {'field': 'bronze', 'aggFunc': 'avg'}],
            rowData=df.to_dict("records"),
            columnSize="sizeToFit",
            dashGridOptions={"animateRows": False}
        ),
    ]
)


if __name__ == "__main__":
    app.run(debug=True, port=8000)
